﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;


/// <summary>
/// Summary description for Cell
/// </summary>
public class Cell {

    private int Channels, Queue, Guard;
    private int InUse, InUseGuard, InUseQueue;

    ArrayList queueTrack = new ArrayList();
    ArrayList exitTrack  = new ArrayList();

    public ArrayList rtnQueueTrack() {
        return queueTrack;
    }

    public ArrayList rtnExitTrack() {
        return exitTrack;
    }

    public int inUse {
        get { return InUse; }
    }
    
    public int queue {
        get { return InUseQueue; }
    }

    public int guard {
        get { return InUseGuard; }
    }

    public bool addCallGuard(int time) {
        if (this.Guard == this.InUseGuard)
            return false;
        this.InUseGuard++;
        queueTrack.Add(time);
        return true;
    }
    public bool addCallQueue(int time) {
        if (this.Queue == this.InUseQueue)
            return false;
        this.InUseQueue++;
        queueTrack.Add(time);
        return true;
    }

    public void addCall() {
        this.InUse++;
    }

    public void removeCall() {
        this.InUse--;
    }

    public bool isFull() {
        if (this.inUse == this.Channels)
            return true;
        return false;
    }

    public bool moveCallGuard_handToreg(int time) {
        //return true on success -- if channels isn't full and a guard channel was moved
        //return 0 on fail
        if (!guardEnable() )
            return false;
        if ( (this.InUse <= this.Channels) && (this.InUseGuard > 0) ) {
            this.InUseGuard--;
            this.InUse++;
            exitTrack.Add(time);
            return true;
        }
        return false;
    }

    public bool moveCallQueue_handToreg(int time) {
        //return true on success; 0 on fail
        if (!queueEnabled() )
            return false;
        if ((this.InUse <= this.Channels) && (this.InUseQueue > 0)) {
            this.InUseQueue--;
            this.InUse++;
            exitTrack.Add(time);
            return true;
        } else
            return false;
    }
    public bool queueEnabled() {
        if (this.Queue == -1)
            return false;
        return true;
    }

    public bool guardEnable() {
        if (this.Guard == -1)
            return false;
        return true;
    }

	public Cell(int chan, int guard, int reserv) {
        this.Channels = chan - guard;
        if (guard == 0)
            this.Guard = -1;
        else
            this.Guard = guard;
        if (reserv == 0)
            this.Queue = -1;
        else
            this.Queue = reserv;
	}
}